package com.kt.controller;

import com.kt.po.Course;
import com.kt.po.Student;
import com.kt.po.Teacher;
import com.kt.service.SchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/SchoolController")
public class SchoolController {
    @Autowired
    private SchoolService schoolService;

    // /SchoolController/findTeacherByTid?tid=
    @RequestMapping("/findTeacherByTid")
    public Teacher findTeacherByTid(int tid){
        return schoolService.findTeacherByTid(tid);
    }

    // /SchoolController/findStudentBySid?sid=
    @RequestMapping("/findStudentBySid")
    public Student findStudentBySid(int sid){
        return schoolService.findStudentBySid(sid);
    }

    // /SchoolController/deleteTeacherById?id=
    @RequestMapping("/deleteTeacherById")
    public Map<String,Integer> deleteTeacherById(int id){
        //int deleteStudentCount = schoolService.deleteStudentByTid(id);
        //int deleteTeacherCount = schoolService.deleteTeacherById(id);
        //Map<String,Integer> map= new HashMap<>();
        //map.put("deleteStudentCount",deleteStudentCount);
        //map.put("deleteTeacherCount",deleteTeacherCount);
        return schoolService.deleteTeacherAndStudentByTid(id);
    }

    // /SchoolController/findTeacherByIdMap?id=
    @RequestMapping("/findTeacherByIdMap")
    public List<Teacher> findTeacherByIdMap(int id){
        return schoolService.findTeacherByIdMap(id);
    }

    // /SchoolController/findStudentBySidMap?sid=
    @RequestMapping("/findStudentBySidMap")
    public Student findStudentBySidMap(int sid){
        return schoolService.findStudentBySidMap(sid);
    }

    // /SchoolController/findAllCourseMap
    @RequestMapping("/findAllCourseMap")
    public List<Course> findAllCourseMap(){
        return schoolService.findAllCourseMap();
    }
}
